<template>
	<view class="u-page">
		<view class="top flex align-center justify-center">
			<view class="flex align-center justify-center box">
				<text v-for="(item, index) in tabList" :key="index" :class="{active: type==item.type}" @click="toTap(item.type)">{{item.name}}</text>
			</view>
		</view>
		<!-- 基本信息 -->
		<view class="u-demo-block" v-if=" type == 1">
			<text class="u-demo-block__title">基础信息</text>
			<view class="u-demo-block__content">
				<u--form
					labelPosition="left"
					labelWidth="200rpx"
					:model="userInfo"
					ref="form1"
				>
					<u-form-item v-for="(item, index) in form.sec1" :key="index" :label="item.name" :required="item.required" borderBottom>
						<!-- 输入框 -->
						<u--input v-if="item.type=='input'" v-model="userInfo[item.key]" :placeholder="item.placeholder" :disabled="item.disabled" border="none"></u--input>
						<!-- 生日选择 -->
						<picker-month-day style="width: 200rpx;height: 50rpx;" v-if="item.type=='birthday'" v-model="userInfo[item.key]"></picker-month-day>
						<!-- 单选 -->
						<view v-if="item.type=='radio'" class="">
							<u-radio-group  v-model="userInfo[item.key]">
								<u-radio
									:customStyle="{margin: '10rpx 20rpx'}"
									v-for="(items, indexs) in item.range"
									:key="indexs"
									:label="items.name"
									:name="items.value"
								>
								</u-radio>
							</u-radio-group>
						</view>
						<!-- 上传图片 -->
						<u-upload v-if="item.type == 'upload' && item.key != 'photo'"
								:fileList="userInfo[item.key]"
								@afterRead="afterRead"
								@delete="deletePic"
								:name="item.key"
								multiple
								:maxCount="1"
								:width="item.width"
								:height="item.height"
							>
							<image v-if="item.hasbackground" :src="item.background_image" mode="widthFix" :style="item.style" ></image>
						</u-upload>
						<cropper v-if="item.type=='upload' && item.key == 'photo'" selWidth="550rpx" selHeight="770rpx" canScale="true" @upload="photoUpload" :avatarSrc="photo" :avatarStyle="item.style">					</cropper>
	
						<!--日期选择器 -->
						<view v-if="item.type == 'date'">
							<uni-datetime-picker type="date" :clear-icon="false" v-model="userInfo[item.key]" />
							</uni-datetime-picker>
						</view>
					</u-form-item>
				</u--form>
			</view>
			<u-button type="primary" text="下一页" customStyle="margin-top: 50px" @click="toNext(2)"></u-button>
		</view>
		<!-- 紧急联系人 -->
		<view class="u-demo-block" v-if=" type == 2">
			<view v-for="(item, index) in form.sec2" :key="index">
				<view class="u-demo-block__title">
					<text>紧急联系人{{index+1}}</text>
					<view class="">
						<uni-icons v-if="form.sec2.length>1" type="minus" size="24" color="#f7b500" @click="minusFamilyMember(index)"></uni-icons>
						<uni-icons v-if="form.sec2.length-1==index && index<3" type="plus" size="24" color="#f7b500" @click="addFamilyMember"></uni-icons>
					</view>
				</view>
				<view class="u-demo-block__content">
					<u--form
						labelPosition="left"
						labelWidth="200rpx"
						:model="userInfo"
						ref="form1"
					>
					
						<u-form-item v-for="(items, indexs) in item" :key="indexs" :label="items.name" borderBottom>
							<u--input v-if="items.type=='input'" v-model="userInfo.family_members[index][items.key]" :placeholder="items.placeholder" border="none"></u--input>
				
						</u-form-item>
					</u--form>
				</view>
			</view>
			<u-button type="primary" text="下一页" customStyle="margin-top: 50px" @click="toNext(3)"></u-button>
		</view>
		<!-- 就读经历 -->
		<view class="u-demo-block" v-if=" type == 3">
			<view v-for="(item, index) in form.sec3" :key="index">
				<view class="u-demo-block__title">
					<text>就读经历{{index+1}}</text>
					<view class="">
						<uni-icons v-if="form.sec3.length>1" type="minus" size="24" color="#f7b500" @click="minusStudyExprience(index)"></uni-icons>
						<uni-icons v-if="form.sec3.length-1==index && index<0" type="plus" size="24" color="#f7b500" @click="addStudyExprience"></uni-icons>
					</view>
				</view>
				<view class="u-demo-block__content">
					<u--form
						labelPosition="left"
						labelWidth="200rpx"
						:model="userInfo"
						ref="form1"
					>
						<u-form-item v-for="(items, indexs) in item" :key="indexs" :label="items.name" borderBottom>
							<u--input v-if="items.type=='input'" v-model="userInfo.studying_experience[index][items.key]" :placeholder="items.placeholder" border="none"></u--input>
							<view v-if="items.type == 'date'">
								<picker mode="date"  fields="month" v-if="items.type == 'date'" @change="dateStudyingChange($event,index,'start_time')" style="display: inline-block;width: 40%; margin-right: 5%;">
								     <u--input v-model="userInfo.studying_experience[index].start_time" placeholder="开始时间" border="none" disabled></u--input>
								</picker>
								
								<picker mode="date"  fields="month" v-if="items.type == 'date'" @change="dateStudyingChange($event,index,'end_time')" style="display: inline-block;width: 40%;">
								     <u--input  v-model="userInfo.studying_experience[index].end_time" placeholder="结束时间" border="none" disabled></u--input>
								</picker>
							</view>
							
							<!-- 单选 -->
							<view v-if="items.type=='radio'" class="">
								<u-radio-group  v-model="userInfo.studying_experience[index][items.key]">
									<u-radio
										:customStyle="{margin: '10rpx 20rpx'}"
										v-for="(itemss, indexss) in items.range"
										:key="indexss"
										:label="itemss.name"
										:name="itemss.value"
									>
									</u-radio>
								</u-radio-group>
							</view>
							
						<view  v-if="items.type=='select'" class="item flex" @click="showPop(index)">
							<input type="text" disabled v-model="userInfo.studying_experience[index][items.key]" placeholder="请选择学历">
							<lzcPicker :ref="'lzcPicker'+index" @change="bindPickerChange1(items.key,$event)" :pickerList="educationList" pickerTittle='选择学历' />
						</view>
					
						</u-form-item>
					</u--form>
				</view>
			</view>
		
			<u-button type="primary" text="下一页" customStyle="margin-top: 50px" @click="toNext(4)"></u-button>
		</view>
		<!-- 工作经验 -->
		<view class="u-demo-block" v-if=" type == 4">
			<view v-for="(item, index) in form.sec4" :key="index">
				<view class="u-demo-block__title">
					<text>工作经验{{index+1}}</text>
					<view class="">
						<uni-icons v-if="form.sec4.length>1" type="minus" size="24" color="#f7b500" @click="minusWorkExprience(index)"></uni-icons>
						<uni-icons v-if="form.sec4.length-1==index && index<2" type="plus" size="24" color="#f7b500" @click="addWorkExprience"></uni-icons>
					</view>
				</view>
				<view class="u-demo-block__content">
					<u--form
						labelPosition="left"
						labelWidth="200rpx"
						:model="userInfo"
						ref="form1"
					>
						<u-form-item v-for="(items, indexs) in item" :key="indexs" :label="items.name" borderBottom>
							<u--input v-if="items.type=='input'" v-model="userInfo.working_experience[index][items.key]" :placeholder="items.placeholder" border="none"></u--input>
						
						<view v-if="items.type == 'date'">
							<picker mode="date"  fields="month" v-if="items.type == 'date'" @change="dateWorkChange($event,index,'start_time')" style="display: inline-block;width: 40%; margin-right: 5%;">
							     <u--input v-model="userInfo.working_experience[index].start_time" placeholder="开始时间" border="none" disabled></u--input>
							</picker>
							
							<picker mode="date"  fields="month" v-if="items.type == 'date'" @change="dateWorkChange($event,index,'end_time')" style="display: inline-block;width: 40%;">
							     <u--input  v-model="userInfo.working_experience[index].end_time" placeholder="结束时间" border="none" disabled></u--input>
							</picker>
						</view>
						</u-form-item>
					</u--form>
				</view>
			</view>
			<u-button type="primary" text="下一页" customStyle="margin-top: 50px" @click="toNext(5)"></u-button>
		</view>
		<!-- 应聘信息 -->
		<view class="u-demo-block" v-if=" type == 5">
			<text class="u-demo-block__title">应聘信息</text>
			<view class="u-demo-block__content">
				<u--form
					labelPosition="left"
					labelWidth="200rpx"
					:model="userInfo"
					ref="form1"
				>
					<u-form-item v-for="(item, index) in form.sec5" :key="index" :label="item.name" :required="item.required" borderBottom>
						<!-- 输入框 -->
						<u--input v-if="item.type=='input'" v-model="userInfo[item.key]" :placeholder="item.placeholder" :disabled="item.disabled" border="none"></u--input>
						<!-- 单选 -->
						<view v-if="item.type=='radio'" class="">
							<u-radio-group  v-model="userInfo[item.key]">
								<u-radio
									:customStyle="{margin: '10rpx 20rpx'}"
									v-for="(items, indexs) in item.range"
									:key="indexs"
									:label="items.name"
									:name="items.value"
								>
								</u-radio>
							</u-radio-group>
						</view>
					</u-form-item>
				</u--form>
			</view>
			<u-button v-if="  userInfo.charge_confirm_time == null " type="primary" text="提交" customStyle="margin-top: 50px" @click="submit"></u-button>
		</view>
	<yfx-tooltip ref="tooltip"></yfx-tooltip>
	<zero-loading v-if="loading == true" type="gear" mask="true" maskOpacity="0.3"></zero-loading>
	</view>
</template>

<script>
	import lzcPicker from '@/components/lzc-picker/lzc-picker.vue'
	import cropper from "@/components/lxiaoxiao-cropper/lxiaoxiao-cropper.vue";
	
	export default {
		components: {
			lzcPicker,
			cropper
		},
		data() {
			return {
				loading    : false,
				showCatePop: false,
				photo      : '/static/image/icon_avatar.png',
				educationList: [
					{id:'本科',name:'本科'},
					{id:'大专',name:'大专'},
					{id:'中专',name:'中专'},
					{id:'高中',name:'高中'},
					{id:'初中',name:'初中'},
					{id:'研究生',name:'研究生'},
				],
				upBaseUrl:this.$http.baseUrl,
				type : '1',
				ocr_idcrad_open : '0',//是否开启身份证识别 1.开启
				tabList: [
					{ name:'基础信息', type: '1'},
					{ name:'紧急联系人', type: '2'},
					{ name:'就读经历', type: '3'},
					{ name:'工作经验', type: '4'},
					{ name:'应聘信息', type: '5'},
				],
				form:{
					sec1:[
						//{type:'datetime', 'name': '日期', key: 'date' },
						{type:'upload', 'name': '一寸照片', key: 'photo' , required: true  , width : '175rpx' , height : '245rpx' ,style : 'width: 175rpx;height: 245rpx;' ,  hasbackground : true , background_image : '/static/image/icon_avatar.png'},
						{type:'upload', 'name': '身份证正面', key: 'card_image_front' , required: true , width : '350rpx' , height : '210rpx' ,style : 'width: 350rpx;height: 210rpx;' ,  hasbackground : true , background_image : '/static/image/card_front.png'},
						{type:'upload', 'name': '身份证反面', key: 'card_image_back' , required: true , width : '350rpx' , height : '210rpx' ,style : 'width: 350rpx;height: 210rpx;' ,  hasbackground : true , background_image : '/static/image/card_back.png'},
						{type:'input', 'name': '中文姓名', key: 'c_name', placeholder:'请输入中文姓名',required: true,disabled:true},
						{type:'input', 'name': '英文姓名', key: 'e_name', placeholder:'请输入英文姓名'},
						{type:'input', 'name': '本人电话', key: 'mobile', placeholder:'请输入本人电话',required: true,disabled:true},
						{type:'input', 'name': '团队', key: 'team', placeholder:'请输入所属团队',required: true,disabled:true},
						{type:'input', 'name': '职位', key: 'position_name', placeholder:'请输入职位',required: true,disabled:true},
						{type:'radio', 'name': '性别', key: 'gender', range: [
							{name: '男', value:1, disabled: false},
							{name: '女', value:2, disabled: false},
						],required: true},
						{type:'input', 'name': '民族', key: 'nation', placeholder:'请输入民族',required: true},
						//{type:'input', 'name': '年龄', key: 'age', placeholder:'请输入年龄',required: true},
						{type:'date', 'name': '出生日期', key: 'date_of_birth', placeholder:'请输入出生日期',required: true},
						{type:'birthday', 'name': '生日(阳历)', key: 'birthday', placeholder:'请输入生日',required: true},
						{type:'input', 'name': '身高(米)', key: 'height', placeholder:'请输入身高(米)',required: true},
						{type:'input', 'name': '体重(公斤)', key: 'weight', placeholder:'请输入体重(公斤)',required: true},
						{type:'radio', 'name': '婚姻状况', key: 'marital_status',required: true, range: [
							{name: '未婚', value:'未婚', disabled: false},
							{name: '已婚', value:'已婚', disabled: false},
							{name: '离异', value:'离异', disabled: false},
							{name: '丧偶', value:'丧偶', disabled: false},
						]},
						{type:'input', 'name': '健康状况', key: 'health_condition', placeholder:'请输入健康状况',required: true},
						{type:'input', 'name': '身份证号码', key: 'card_no', placeholder:'请输入身份证号码',required: true},
						{type:'input', 'name': '身份证地址', key: 'permanent_address', placeholder:'请输入身份证地址',required: true},
						{type:'radio', 'name': '户籍性质', key: 'registered_residence', range: [
							{name: '城镇户口', value:'1', disabled: false},
							{name: '农村户口', value:'2', disabled: false},
							// {name: '本市农村', value:'3', disabled: false},
							// {name: '外阜农村', value:'4', disabled: false},
						],required: true},
						{type:'input', 'name': '本地住址', key: 'address_in_zhengzhou', placeholder:'请输入本地住址',required: true},
						{type:'input', 'name': '籍贯', key: 'hometown', placeholder:'请输入籍贯',required: true},
						{type:'input', 'name': '个人邮箱', key: 'email', placeholder:'请输入个人邮箱'},
						//{type:'input', 'name': '所获(资格)证书', key: 'certificate', placeholder:'请输入所获(资格)证书'},
					],
					sec2:[],
					sec3:[],
					sec4:[],
					sec5:[
						// {type:'radio', 'name': '应聘方式', key: 'application_method', range: [
						// 	{name: '外招', value:'1', disabled: false},
						// 	{name: '推荐', value:'2', disabled: false},
						// ],required: true},
						{type:'input', 'name': '推荐人姓名', key: 'referee_name', placeholder:'暂无推荐人信息',disabled:true},
						//{type:'input', 'name': '推荐人职务', key: 'referee_position', placeholder:'请输入推荐人职务'},
						{type:'radio', 'name': '是否有亲属 在与本公司经营同类型公司任职', key: 'relatives_appoint', range: [
							{name: '否', value:'1', disabled: false},
							{name: '是', value:'2', disabled: false},
						],required: true},
						{type:'input', 'name': '亲属关系', key: 'relatives_relation', placeholder:'请输入亲属关系'},
						{type:'input', 'name': '姓名', key: 'relatives_name', placeholder:'请输入姓名'},
						{type:'input', 'name': '公司名称', key: 'relatives_company_name', placeholder:'请输入公司名称'},
						{type:'input', 'name': '职务', key: 'relatives_position', placeholder:'请输入职务'},
					]
				},
				userInfo:{
					photo  : [],
					card_image_front  : [],
					card_image_back   : [],
					c_name : '',
					e_name : '',
					team   : '',
					position : '',
					nation : '',
					gender : '',
					age    : '',
					date_of_birth : '',
					birthday      : '',
					height : '',
					weight : '',
					card_no : '',
					marital_status : '',
					health_condition : '',
					permanent_address : '',
					registered_residence : '',
					address_in_zhengzhou : '',
					mobile               : '',
					hometown             : '',
					email                : '',
					certificate          : '',
					family_members       : [], //紧急联系人
					studying_experience  : [], //就读经历
					working_experience : [], //工作经验
					application_method: '',
					referee_name: '',
					referee_position: '',
					relatives_appoint: '',
					relatives_relation: '',
					relatives_name: '',
					relatives_company_name: '',
					relatives_position: '',
					charge_confim_time : null, //主管确认时间
				},
				status : 0,
				rules: {},
				familyItem:[
					{type:'input', 'name': '姓名', key: 'name', placeholder:'请输入姓名'},
					{type:'input', 'name': '关系', key: 'relation', placeholder:'请输入关系'},
					//{type:'input', 'name': '年龄', key: 'age', placeholder:'请输入年龄'},
					//{type:'input', 'name': '工作单位', key: 'unit', placeholder:'请输入工作单位'},
					//{type:'input', 'name': '地址', key: 'address', placeholder:'请输入地址'},
					{type:'input', 'name': '电话', key: 'mobile', placeholder:'请输入电话'},
				],
				studyItem:[
					{type:'select', 'name': '学历', key: 'education', placeholder:'请输入学历'},
					{type:'input', 'name': '专业', key: 'major', placeholder:'请输入专业'},
					{type:'input', 'name': '学校名', key: 'school_name', placeholder:'请输入学校名'},
					{type:'date', 'name': '时间', key: 'period', placeholder:'请输入时间 年/月至年/月'},
					//{type:'input', 'name': '是否毕业', key: 'graduated', placeholder:'请输入是否毕业'},
					//{type:'input', 'name': '是否全日制', key: 'diploma', placeholder:'请输入是否全日制'},
					{type:'radio', 'name': '是否毕业', key: 'graduated', range: [
						{name: '是', value:'是', disabled: false},
						{name: '否', value:'否', disabled: false},
					],required: true},
					{type:'radio', 'name': '是否全日制', key: 'diploma', range: [
						{name: '是', value:'是', disabled: false},
						{name: '否', value:'否', disabled: false},
					],required: true},
				],
				workItem:[
					{type:'input', 'name': '公司名称', key: 'company_name', placeholder:'请输入公司名称'},
					{type:'date', 'name': '时间', key: 'period', placeholder:'请输入时间 年/月至年/月'},
					{type:'input', 'name': '职位', key: 'position', placeholder:'请输入职位'},
					{type:'input', 'name': '每月工资', key: 'salary', placeholder:'请输入每月工资'},
					{type:'input', 'name': '电话', key: 'mobile', placeholder:'请输入电话'},
					{type:'input', 'name': '辞职原因', key: 'leaving_reason', placeholder:'请输入辞职原因'},
				]
			}
		},
		onLoad() {
			this.getOcrCfg();
			this.getUserInfo();	
		},
		onReady() {
			// 如果需要兼容微信小程序，并且校验规则中含有方法等，只能通过setRules方法设置规则
			// this.$refs.form1.setRules(this.rules)
		},
		methods: {
			showPop(index){
				this.$refs[`lzcPicker${index}`][0].handleShow()
			},
			
			bindPickerChange1(key,e){
				this.userInfo.studying_experience[0][key] = e.id;
			},
			//获取ocr配置
			getOcrCfg(){
				//let param = this.userInfo;
				this.$http.getOcrCfg({}).then(res => {
					if (res.code == 1) {
						this.ocr_idcrad_open   = res.data.ocr_idcrad_open;
					}
				});
			},
		    dateStudyingChange(e,index,key){
		      this.userInfo.studying_experience[index][key] = e.detail.value
		    },
			dateWorkChange(e,index,key){
		      this.userInfo.working_experience[index][key] = e.detail.value
		    },
			// 新增紧急联系人
			addFamilyMember(){
				this.form.sec2.push(this.familyItem)
				this.userInfo.family_members.push({
					'name' : '',
					'relation' : '',
					'age' : '',
					'unit' : '',
					'address' : '',
					'mobile' : '',
				})
			},
			// 新增就读经历
			addStudyExprience(){
				this.form.sec3.push(this.studyItem)
				this.userInfo.studying_experience.push(					{
					'education': '',
					'major': '',
					'school_name': '',
					//'period': '',
					'start_time': '',
					'end_time': '',
					'graduated': '',
					'diploma': ''
				})			
			},
			// 新增工作经验
			addWorkExprience(){
				this.form.sec4.push(this.workItem)
				this.userInfo.working_experience.push(					{
					'company_name' : '',
					//'period' : '',
					'start_time': '',
					'end_time': '',
					'position' : '',
					'salary' : '',
					'mobile' : '',
					'leaving_reason' : '',
				})
			},
			minusFamilyMember(index){
				this.userInfo.family_members.splice(index, 1)
				this.form.sec2.splice(index, 1)
			},
			minusStudyExprience(index){
				this.userInfo.studying_experience.splice(index, 1)
				this.form.sec3.splice(index, 1)
			},
			minusWorkExprience(index){
				this.userInfo.working_experience.splice(index, 1)
				this.form.sec4.splice(index, 1)
			},
			toNext(e){
				this.type = e;
			},
			toTap(type){
				if(this.type == type){
					return
				}
				this.type = type;
			},
	
			submit() {
				this.userInfo.birthday =this.userInfo.birthday + '';
				let param = this.userInfo;
				this.$http.saveUserInfo(param).then(res => {
					if (res.code == 1) {
						uni.showToast({
							title: res.msg,
							duration: 2000,
							complete: function () {
							        // 2秒后关闭 toast 并返回上一页
							        setTimeout(function () {
										let pages = getCurrentPages();
										let prevPage = pages[pages.length - 2];//上一个页面
										//直接调用上一个页面的setData()方法，把数据存到上一个页面中去
										prevPage.setData({
											 isRefresh: 1 
										})
							           	uni.navigateBack(1);
							        }, 2000);
							    }
						});
					
					}else{
						this.$refs.tooltip.open({
							msg: '提示',//标题
							content: res.msg,//提示内容
							showCancel: false//不显示取消按钮
						})
					}
				});
				
			},
			test(){
				const url = '/pages/other/camera';
				uni.navigateTo({
					url
				})
				console.log('相机初始化完成')
			},
			reset() {
				const validateList = ['userInfo.name', 'userInfo.sex', 'radiovalue1', 'intro',
				'hotel', 'code', 'userInfo.birthday']
				this.$refs.form1.resetFields()
				this.$refs.form1.clearValidate()
				setTimeout(()=>{
					this.$refs.form1.clearValidate(validateList)
					// 或者使用 this.$refs.form1.clearValidate()
				},10)
			},
			getUserInfo() {
				let param = {};
				this.$http.getUser(param).then(res => {
					if (res.code == 1) {
						this.status   = res.data.status;
						this.userInfo = res.data;
						if(res.data.photo.length != 0){
							this.photo    = res.data.photo[0].url;
						}
						if(res.data.family_members.length>0){
							for(let i=0; i<res.data.family_members.length;i++){
								this.form.sec2.push(this.familyItem)
							}
						}else{
							this.addFamilyMember()
						}
						if(res.data.studying_experience.length>0){
							for(let i=0; i<res.data.studying_experience.length;i++){
								this.form.sec3.push(this.studyItem)
							}
						}else{
							this.addStudyExprience()
						}
						if(res.data.working_experience.length>0){
							for(let i=0; i<res.data.working_experience.length;i++){
								this.form.sec4.push(this.workItem)
							}
						}else{
							this.addWorkExprience()
						}	
					}else{
						if(res.code == 401){
							var code = '';
							uni.login({
								provider: 'weixin',
								success: function(logRes) {
									code = logRes.code;
								}
							});
							// 获取code
							
							uni.getUserProfile({
								desc: '作为展示',
								success: res => {
									let param = {
										code: code,
										iv: res.iv,
										encryptedData: res.encryptedData,
										rawData: res.rawData,
										signature: res.signature,
										nickname: res.userInfo.nickName,
										avatar: res.userInfo.avatarUrl,
									};
									that.$http.authorization(param).then(res => {
										uni.hideToast();
										if (res.code == 1) {
											uni.setStorageSync('token', res.data.token);
											uni.setStorageSync('mobile',res.data.mobile?res.data.mobile:'');
											
											this.getUserInfo();
											
										}
									});
								},
								fail: err => {
									console.log('获取失败', err);
								}
							});
							
						}else{
							this.$refs.tooltip.open({
								msg: '提示',//标题
								content: res.msg,//提示内容
								showCancel: false,//不显示取消按钮
								confirm: () => {
									uni.navigateBack({
										delta: 1
									});
								} 
							})
							// uni.showToast({
							// 	title: res.msg,
							// 	icon : 'error',
							// 	duration: 2000,
							// 	// complete: () => {
							// 	// 	uni.navigateBack({
							// 	// 		delta: 1
							// 	// 	});
							// 	// }
							// });
						}
					}
					
					
				})
			},
			
		// 删除图片
			deletePic(event) {
				this.userInfo[`${event.name}`].splice(event.index, 1)
			},
		      // 新增图片
		      async afterRead(event) {
		        // 当设置 multiple 为 true 时, file 为数组格式，否则为对象格式
		        let lists = [].concat(event.file)
		        let fileListLen = this.userInfo[`${event.name}`].length
		        lists.map((item) => {
		          this.userInfo[`${event.name}`].push({
		            ...item,
		            status: 'uploading',
		            message: '上传中'
		          })
		        })
		        for (let i = 0; i < lists.length; i++) {
		          const result = await this.uploadFilePromise(lists[i].url)
		          console.log(result);
		          let item = this.userInfo[`${event.name}`][fileListLen]
		          this.userInfo[`${event.name}`].splice(fileListLen, 1, Object.assign(item, {
		            status: 'success',
		            message: '',
		            url    :result
		          }))
		          fileListLen++;
				//身份证正面上传  调用身份证识别接口
		         if( event.name == 'card_image_front' && this.ocr_idcrad_open == '1'){
					 this.ocrIdCard(result);
				 }
		        }
		      },
			uploadFilePromise(url) {
				this.loading = true;
				return new Promise((resolve, reject) => {
					let a = uni.uploadFile({
						url: this.upBaseUrl + 'common/uploadImg',
						filePath: url,
						name: 'file',
						header: {
							'TOKEN': uni.getStorageSync('token')
						},
						formData: {},
						success: (res) => {
							setTimeout(() => {
								this.loading = false;
								resolve(JSON.parse(res.data).data.full_url)
							}, 1000)
						}
					});
				})
			},
	
			
			//调用身份证识别接口
			ocrIdCard(url){
				//let param = this.userInfo;
				this.$http.ocrIdCard({ 'image' : url}).then(res => {
					if (res.code == 1) {
						this.userInfo.c_name            = res.data.name;
						this.userInfo.permanent_address = res.data.address;
						this.userInfo.nation 			= res.data.nationality;
						this.userInfo.card_no 			= res.data.num;
						this.userInfo.gender 			= res.data.sex;
						this.userInfo.date_of_birth     = res.data.birth;
						this.userInfo.birthday          = res.data.birthday;
						//this.userInfo.age               = res.data.age;
					}else{
						this.$refs.tooltip.open({
							msg: '提示',//标题
							content: res.msg,//提示内容
							showCancel: false//不显示取消按钮
						})
					}
				});
			},
			
			//上传返回图片
			async photoUpload(rsp) {
				console.log('upload')
			  const self = this;
			  const result = await this.uploadFilePromise(rsp.path);
			  console.log(result);
			  let fileListLen = this.userInfo['photo'].length
			  console.log(fileListLen);
			  this.userInfo['photo'] = [{
	              status: 'success',
	              message: '',
	              url    :result
	            }];
				this.photo = result;
			  // rsp.avatar.imgSrc = rsp.path; //更新头像方式二
			},
			
	
				
		}
	}
</script>
<style lang="scss" scoped>
	.u-page{
		background: #fff;
		padding:0rpx 20rpx 50rpx
	}
	.top{
		position: sticky;
		top: 0;
		height: 120rpx;
		border-bottom: 2rpx solid #eee;
		background: #fff;
		z-index:5;
		
		.box{
			border: 2rpx solid #3784ff;
			width: 800rpx;
			border-radius: 10rpx;
			
			text{
				width: 50%;
				height: 74rpx;
				text-align: center;
				line-height: 74rpx;
				color: #3784ff;
				border-right: 1rpx solid #3784ff;
				
				&:nth-last-child(1){
					border: 0;
				}
			}
			
			.active{
				background-color:#3784ff;
				color: #fff;
			}
		}
	}
	.u-demo-block{
		.u-demo-block__title{
			display: flex;
			align-items: center;
			justify-content: space-between;
			color: #f7b500; 
			padding: 20rpx 0 10rpx;
		}
		::v-deep .u-form-item{
			.u-radio-group{
				flex-wrap: wrap;
			}
		}
	}
	.selestDate{
	        border: 2rpx solid #e5e5e5;
	        border-radius: 100rpx;
	        background-color: #EAF4FF;
	        color: #3399FF;
	        font-size: 30rpx;
	        font-family: PingFangSC;
	        font-weight: Regular;
	        max-width: 600rpx;
	        height: 70rpx;
	        line-height: 70rpx;
	        padding-left: 30rpx;
	    }
</style>
